package com.smart.manager.finance.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.ArcoTips;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.manager.finance.entities.bodys.RAccountAlipay;
import com.smart.manager.finance.entities.models.FinanceAccountAlipay;
import com.smart.manager.finance.repository.AccountAlipayRepository;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import java.util.List;


/**
 * @author Administrator
 */

@Api(tags = "支付宝账户管理")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "finance/account/alipay")
@RequiredArgsConstructor
public class AccountAlipayApi {

    private final AccountAlipayRepository accountAlipayRepository;


    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询支付宝账户")
    @SaCheckPermission("finance:account:alipay:pageList")
    public AjaxResult<Page<FinanceAccountAlipay>> pageList(@Validated RAccountAlipay.SearchBody body) {
        Page<FinanceAccountAlipay> result = accountAlipayRepository.pageList(body);
        return AjaxResult.data(result);
    }


    @PostMapping(value = "add")
    @ApiOperation(value = "新增支付宝账户")
    @SaCheckPermission("finance:account:alipay:add")
    public AjaxResult<String> add(@RequestBody @Validated RAccountAlipay.EditBody body) {
        accountAlipayRepository.add(body);
        return AjaxResult.success();
    }


    @PutMapping(value = "update/{id}")
    @ApiOperation(value = "修改支付宝账户")
    @SaCheckPermission("finance:account:alipay:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RAccountAlipay.EditBody body) {
        accountAlipayRepository.update(id, body);
        return AjaxResult.success();
    }


    @DeleteMapping(value = "delete")
    @ApiOperation(value = "删除支付宝账户")
    @SaCheckPermission("finance:account:alipay:delete")
    public AjaxResult<Integer> delete(@RequestBody @NotEmpty(message = ArcoTips.PK_EMPTY) List<Long> ids) {
        int x = accountAlipayRepository.delByIds(ids);
        return AjaxResult.delSuccess(x);
    }

}
